package cn.fuxi2022.module.schedule;

import cn.fuxi2022.module.info.service.GroupStudentInfoCountService;
import cn.fuxi2022.module.pay.service.GroupStudentPayLogCountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 定时器
 *
 * @author Fuxi
 */
@Component
@Slf4j
public class ScheduledTask {

    @Autowired
    private GroupStudentInfoCountService groupStudentInfoCountService;

    @Autowired
    private GroupStudentPayLogCountService groupStudentPayLogCountService;

    /**
     * 在每天凌晨1点，把统计数据都刷新一次
     * 执行统计方法
     */
    @Scheduled(cron = "0 0 1 * * ?")  // 只能写六位！！！
    public void task() {
        groupStudentInfoCountService.groupStudentInfoRefresh();
        groupStudentInfoCountService.groupStudentInfoCount();

        groupStudentPayLogCountService.groupStudentPayLogRefresh();
        groupStudentPayLogCountService.groupStudentPayLogCount();

        log.info("{}定时执行统计方法，时间为：{}", this, new Date());
    }
}